package org.sunrise.game.common.network.message;

import org.sunrise.game.common.log.LogCore;
import org.sunrise.game.common.message.MessageUtils;
import org.sunrise.game.common.network.server.BaseServerManager;

/**
 * 服务器默认消息管理器
 * 处理消息,回发给客户端
 */
public class ServerMessageManager extends BaseMessageManager {
    public ServerMessageManager(String nodeId) {
        super(nodeId);
    }

    @Override
    protected void pulseHandlerOne(Object data) {
        var message = MessageUtils.fromMessage((byte[]) data, BaseMessage.class);
        LogCore.Server.debug("recv msg, cur NodeId = { {} }, from NodeId = { {} }, messageId = { {} }, data = { {} }", getNodeId(), message.getNodeId(), message.getMessageId(), message.getMsg());

        var sendMsg = new BaseMessage(getNodeId(), message.getNodeId(), message.getMessageId(), message.getMsg());
        BaseServerManager.sendToClient(sendMsg);
    }
    @Override
    protected void pulseSenderOne(Object data) {
        BaseServerManager.sendMsgToClient((BaseMessage) data);
    }
}
